$(function(){
    $.getJSON("/api/product/index/catelog.json",function (data) {
        var ctgall=data;
        $(".first-class-a").each(function(){
            var ctgnums= $(this).attr("ctg-data");
            if(ctgnums){
                var panel=$("<ul class=\"dropdown-menu secound-menu\"></ul>");
                var  ctgnumArray = ctgnums.split(",");
                $.each(ctgnumArray,function (i,ctg1Id) {
                    var ctg2list= ctgall[ctg1Id];
                    $.each(ctg2list,function (i,ctg2) {
                        var cata2link=$("<li class=\"dropdown-submenu\"><a href=\"#\">"+ctg2.name+"</a>");
                        var ul=$("<ul class=\"dropdown-menu fourth-menu\">\n" +
                            "     </ul>");
                        var  ctg3List=ctg2["catelog3VoList"];
                        var len=0;
                        $.each(ctg3List,function (i,ctg3) {
                            var cata3link = $("<li><a href=\"http://localhost:88/api/search/list/list.html?catalog3Id="+ctg3.id+"\">"+ ctg3.name +"</a></li>");
                            ul.append(cata3link)
                            len++;
                        });
                        if(typeof(ctg3List) !== "undefined" && len != 0){
                            cata2link.append(ul);
                            panel.append(cata2link);
                        }else{
                            cata2link=$("<li><a href=\"http://localhost:88/api/search/list/list.html?catalog3Id="+ctg2.id+"\">"+ctg2.name+"</a>");
                            panel.append(cata2link);
                        }
                    });

                });
                $(this).after(panel);
                // $(this).parent().addClass("header_li2");
                console.log($(this).parent());
            }
        });
    });
});